define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xlzxinfo/xlzxinfo/index' + location.search,
                    add_url: 'xlzxinfo/xlzxinfo/add',
                    edit_url: 'xlzxinfo/xlzxinfo/edit',
                    del_url: 'xlzxinfo/xlzxinfo/del',
                    multi_url: 'xlzxinfo/xlzxinfo/multi',
                    import_url: 'xlzxinfo/xlzxinfo/import',
                    table: 'mental_xlzxinfo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'typeStr', title: __('Typestr'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        // {field: 'isExp', title: __('Isexp'), searchList: {"1":__('Isexp 1'),"0":__('Isexp 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'full_name', title: __('Full_name'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'id_number', title: __('Id_number'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        // {field: 'certificate_image', title: __('Certificate_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'is_hot', title: __('精选'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime')},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $(document).on('click', '.btn-assessment', function () {
                var ids = Table.api.selectedids(table);
                var title = '咨询师方向评估';
                Fast.api.open(Fast.api.fixurl("xlzxinfo/assessment/view/ids/"+ids), title, { area: ["75%", "95%"] });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-status").change(function(){
                var type_value = $("#c-status").val();
                if(type_value==2){
                    $('form[role=form]').validator("setField", {
                        "row[reason]": "required",
                    });
                }else{
                    $('form[role=form]').validator("setField", {
                        "row[reason]": null,
                    });
                }
            })
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
